<template>
  <div class="news">
    <!-- 导航区 -->
    <ul>
      <li v-for="news in newsList" :key="news.id">
          <!--第一种写法-->
<!--        <RouterLink :to="`/Detail?id=${news.id}&title=${news.title}&content=${news.content}`" class="news-link">-->
<!--        </RouterLink>-->

        <!--第二种写法-->
        <RouterLink
           :to="{
            path:'/Detail',
            query:{
              id:news.id,
              title:news.title,
              content:news.content,
            }
          }"
        >
          {{news.title}}
        </RouterLink>
      </li>
    </ul>
    <!-- 展示区 -->
    <div class="news-content">
      <RouterView></RouterView>
    </div>
  </div>
</template>

<script setup lang="ts">
// 你可以在这里添加逻辑代码
import { reactive } from "vue";
import { RouterView } from "vue-router";

let newsList = reactive([
  { id: 1, title: '一种抗癌食物', content: '西兰花' },
  { id: 2, title: '如何一夜暴富', content: 'Java' },
  { id: 3, title: '震惊，万万没想到', content: '明天要比赛' },
]);
</script>

<style scoped>
.news {
  background-color: #f9f9f9;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  max-width: 800px;
  margin: 0 auto;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  margin-bottom: 10px;
}

.news-link {
  text-decoration: none;
  color: #333;
  font-weight: bold;
  transition: color 0.3s ease, background-color 0.3s ease;
  padding: 5px 10px;
  border-radius: 5px;
  display: inline-block;
  width: 100%;
  text-align: left;
}

.news-link:hover {
  color: #fff;
  background-color: #007bff;
}
</style>
